package com.talkyun.utils.json;

import java.util.Date;

public class JSONArray {
    private com.alibaba.fastjson.JSONArray array;

    JSONArray(com.alibaba.fastjson.JSONArray array) {
        this.array = (array == null) ? new com.alibaba.fastjson.JSONArray() : array;
    }

    public JSONArray add(Object obj) {
        if (obj instanceof JSONObject) {
            this.array.add(((JSONObject) obj).getRawObject());
        } else {
            this.array.add(obj);
        }
        return this;
    }

    protected com.alibaba.fastjson.JSONArray getRawArray() {
        return array;
    }

    public JSONObject getJSONObject(int index) {
        com.alibaba.fastjson.JSONObject json = array.getJSONObject(index);
        return json == null ? null : new JSONObject(json);
    }

    public Object get(int index) {
        return array.get(index);
    }

    public Object getObject(int index, Class<?> clazz) {
        return array.getObject(index, clazz);
    }

    public Date getDate(int index) {
        return array.getDate(index);
    }

    public Integer getInteger(int index) {
        return array.getInteger(index);
    }

    public String getString(int index) {
        return array.getString(index);
    }

    public Long getLong(int index) {
        return array.getLong(index);
    }

    public int size() {
        return array.size();
    }

    @Override
    public String toString() {
        return array == null ? null : array.toJSONString();
    }
}
